<template>
  <!-- 领奖地址界面 -->
  <view class="content">
    <view class="font-box" >
      <view  style="margin-bottom: 20rpx; font-size: 28rpx; color: #000000;font-weight: 600;">
        收件地址:
      </view>
      <u--textarea height="100" v-model="value" placeholder="请输入地址"  count ></u--textarea>
     <view style="display: flex;justify-content: center; padding: 0 25%; margin-top: 30rpx;" >
       <u-button type="success" @click="submit" text="确定"></u-button>
     </view>
    </view>
    <u-modal :show="show" :showCancelButton='true' :title="thisTitle" @confirm="confirm" @cancel="show = false" width="250px" ></u-modal>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        show:false,
        thisTitle:'确定地址?',
        value:'',
    goodsDetails:{}
      };
    },
    onLoad(options) {
      console.log(JSON.parse(options.item))
      this.goodsDetails = JSON.parse(options.item)
    },
    methods:{
      submit() {
        this.show = true
      },
     async confirm() {
        this.show= false
        const obj = {
          awardType: 1,
          createTime: this.goodsDetails.createTime,
          id: this.goodsDetails.id,
          prizeId: this.goodsDetails.prizeId,
          mailAddress: this.value,
          openId: this.goodsDetails.openId,
          orderNo: this.goodsDetails.orderNo,
          jobSeeker: uni.getStorageSync('userinfo'),
          prize: {
            createTime: this.goodsDetails.prize.createTime,
            exchangeNum: this.goodsDetails.prize.exchangeNum,
            id: this.goodsDetails.prize.id,
            isShelf: this.goodsDetails.prize.isShelf,
            needIntegral: this.goodsDetails.prize.needIntegral,
            prizeAvatar: this.goodsDetails.prize.prizeAvatar,
            prizeIntroduce: this.goodsDetails.prize.prizeIntroduce,
            prizeName: this.goodsDetails.prize.prizeName,
            prizeTotalNum: this.goodsDetails.prize.prizeTotalNum
          },
        }
        const { data } = await uni.$http.post('/prize/writeAwardType' , obj)
        console.log(data)
        if(data.statusCode !== 200) {
          return 
        }else {
          uni.$u.toast(data.message)
            this.value = ''
           let pages = getCurrentPages()
           	// 获取上一页栈
           	let prevPage = pages[ pages.length - 2 ]
           	// 触发上一页 upData 函数(并携带参数)
           	prevPage.$vm.sonEvent('我现在更新啦~')
                 
          uni.navigateBack({
            delta: true
          })
        }
      }
    }
  }
</script>

<style lang="scss">
.content {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  .font-box {
    width: 100%;
    padding: 0 30rpx;
    background-color: #FFFFFF;
  }
}
</style>
